<?php
/*
Template Name: Gallery Template
*/

get_header();
get_template_part( 'slider2' );
?>	
	<div id="content">
		<div class="template clear-fix" id="casestudy">
			<div class="tpl-left">
				<div class="heading-1 clear-fix">
					<h2>Galleri</h2>
				</div>
				<div id="service-list">
					<ul id="lstSupport">
						<?php 
							global $post;
							global $wpdb;
							global $wp_query;
							$paged = $wp_query->query_vars["paged"];
							$permalink = get_permalink();
							$gllr_options = get_option( 'gllr_options' );
							if( substr( $permalink, strlen( $permalink ) -1 ) != "/" )
							{
								if( strpos( $permalink, "?" ) !== false ) {
									$permalink = substr( $permalink, 0, strpos( $permalink, "?" ) -1 )."/";
								}
								else {
									$permalink .= "/";
								}
							}
							$count = 0;
							$args = array(
								'post_type'					=> 'gallery',
								'post_status'				=> 'publish',
								'orderby'					=> 'post_date',
								'posts_per_page'			=> -1
							);
							$second_query = new WP_Query( $args );
							$count_all_albums = count($second_query->posts);
							$per_page = 5;
							if( $paged != 0 )
								$start = $per_page * ($paged - 1);
							else
								$start = $per_page * $paged;
							if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post();
								if( $count < $start ) {
									$count++;
									continue;
								}
								if( ( $count - $start ) > $per_page - 1 )
									break;
		
							$attachments = get_children( 'post_parent='.$post->ID.'&post_type=attachment&post_mime_type=image&numberposts=1' );
							$id = key($attachments);
							$image_attributes = wp_get_attachment_image_src( $id, 'album-thumb' );
							$count++;
						?>
						<li>							
							<a href="<?php echo $permalink; echo basename( get_permalink( $post->ID ) ); ?>">
								<?php echo $post->post_title; ?>
							</a>							
						</li>						
						<?php endwhile; endif; wp_reset_query(); ?>						
					</ul>
				</div>
			</div>
			<div class="tpl-right">
				<div class="heading clear-fix">
					<h2>Butik & forretning</h2>
				</div>			
				<div class="gallery-wrapper">
					<!--<ul id="gallery-list">
						<?php for($i = 0; $i < 16; $i++){ ?>
						<li>
							<a href="<?php echo get_template_directory_uri(); ?>/images/temp-5.jpg" class="mainImage">
								<img src="<?php echo get_template_directory_uri(); ?>/images/temp-3.jpg" alt="" />
							</a>
							<a href="<?php echo get_template_directory_uri(); ?>/images/temp-5.jpg" class="zoomIcon" rel="prettyPhoto[demo]">
								<img src="<?php echo get_template_directory_uri(); ?>/images/hoverImage.png" alt="" />
							</a>
						</li>
						<?php } ?>
					</ul>
					--><div class="clear"></div>
				</div>
			</div>		
		</div>
	</div>
<?php get_footer(); ?>